<template>
	<view class="view">
		<view class="head">
			<image src="https://yixianfeng.oss-cn-beijing.aliyuncs.com/static/images/bg_sign.png" mode="widthFix">
			</image>
			<view class="integral">
				<view>可用积分</view>
				<view>{{account.accountBalance || 0}}</view>
			</view>
			<view class="details" @click="to('/pages/other/integral/details')">明细</view>
		</view>
		<view class="section">
			<view class="top">
				<image src="/static/images/ic_map.png"></image>
				<view class="info">
					<view>已签到<text>{{signInfo.consecutiveDays || 0}}天</text></view>
					<view>连续签到可以获得更多积分哦～</view>
				</view>
				<view class="recharge" style="background-color: #eb0000; margin-top: -40rpx;"
					@click="to('/pages/other/deposit/deposit')" v-if="isStartPayment ==1">
					<text>充值</text>
				</view>
				<view class="recharge" style="background-color: #ee7f1e; margin-top: 60rpx;"
					@click="to('/pages/other/withdrawCash/withdrawCash')" v-if="isStartWithdraw ==1">
					<text>提现</text>
				</view>
			</view>
			<view class="grid">
				<view class="item" v-for="(item,index) of 8" :key="index">
					<view v-if="item < signInfo.consecutiveDays" class="active">
						<view>已签到{{item + 1}}天</view>
						<view>积分+{{item + 1 > 7 ? 7 : item + 1}}</view>
						<image src="/static/images/ic_signediny.png"></image>
					</view>
					<view v-else class="common">
						<view>累计{{item + 1}}天</view>
						<image src="/static/images/ic_goldcoin.png"></image>
						<view>积分+{{item + 1 > 7 ? 7 : item + 1}}</view>
					</view>
				</view>
			</view>
			<view v-if="signInfo.isSignIn == 0" class="btn" @click="signIn()">签到</view>
			<view v-else class="btn gray">已签到</view>
		</view>
		<!-- 弹窗 -->
		<view v-if="showTip" class="dialog">
			<view class="mask"></view>
			<view class="container">
				<icon type="cancel" color="#FFFFFF" @click="showTip = false"></icon>
				<image src="https://yixianfeng.oss-cn-beijing.aliyuncs.com/static/images/bg_success.png"
					mode="widthFix">
				</image>
				<view class="info">
					<view>提示</view>
					<view>您已经成功签到<text>{{signInfo.consecutiveDays}}</text>天</view>
					<view class="btn" @click="showTip = false">知道了</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getConfig
	} from '@/apis/request.js';

	export default {
		data() {
			return {
				account: {
					accountBalance: 0
				},
				signInfo: {
					consecutiveDays: 0
				},
				showTip: false,
				isStartPayment: 0,
				isStartWithdraw: 0,
			};
		},
		onLoad() {
			this.init();
		},
		methods: {
			init() {
				this.getAccountInfo();
				this.getSignInfo();
				this.getConfig();
			},
			getAccountInfo() {
				this.$api.http('/user/userAccountInfo/getAccountInfoByUserId', 'GET', {
					userId: uni.getStorageSync('userInfo').id
				}, res => {
					if (res.data.code == 200) {
						this.account = res.data.result;
					} else {
						this.$Toast(res.data.message || '请求失败，请重试！');
					}
				});
			},
			getSignInfo() {
				this.$api.http('/user/userSignInfo/getUserSignInfo', 'GET', {}, res => {
					if (res.data.code == 200) {
						this.signInfo = res.data.result;
					} else {
						this.$Toast(res.data.message || '请求失败，请重试！');
					}
				});
			},
			getConfig() {
				getConfig().then(res => {
					this.isStartPayment = res.isStartPayment;
					this.isStartWithdraw = res.isStartWithdraw;
				})
			},
			signIn() {
				this.$api.http('/user/userSignInfo/userSign', 'GET', {}, res => {
					if (res.data.code == 200) {
						this.init();
						this.showTip = true;
					} else {
						this.$Toast(res.data.message || '请求失败，请重试！');
					}
				});
			},
			to(url) {
				uni.navigateTo({
					url
				});
			},
		},
	}
</script>

<style lang="less" scoped>
	.view {
		width: 100%;
		min-height: 100vh;
		background-color: #f1efef;

		.head {
			position: relative;

			image {
				width: 100%;
			}

			.integral {
				position: absolute;
				left: 0;
				top: calc(50% - 80rpx);
				right: 0;
				color: #F8EDD3;
				text-align: center;

				view {
					font-size: 38rpx;

					&:first-child {
						font-size: 28rpx;
					}
				}
			}

			.details {
				position: absolute;
				top: 0;
				right: 20rpx;
				width: 80rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 28rpx;
			}
		}

		.section {
			position: relative;
			z-index: 9;
			margin-left: 20rpx;
			margin-top: -150rpx;
			margin-right: 20rpx;
			background-color: #FFFFFF;
			border-radius: 30rpx;

			.top {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 30rpx;

				image {
					width: 115rpx;
					height: 88rpx;
				}

				.info {
					flex: 1;
					margin-left: 20rpx;
					font-size: 28rpx;

					view {
						font-size: 24rpx;
						color: #999999;

						&:first-child {
							font-size: 28rpx;
							color: #333333;

							text {
								margin-left: 20rpx;
								font-size: 36rpx;
								color: #F10000;
							}
						}
					}
				}

				.recharge {
					display: inline-block;
					background-color: #eb0000;
					line-height: 35rpx;
					padding: 5rpx 25rpx;
					border-radius: 60rpx;
					position: absolute;
					left: 550rpx;

					text {
						font-size: 24rpx;
						color: white;
					}
				}
			}

			.grid {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				border-top: 1rpx solid #F1F1F1;
				padding: 20rpx;

				.item {
					margin: 10rpx;
					width: 147.5rpx;

					.common {
						height: 150rpx;
						padding: 20rpx 0;
						text-align: center;
						font-size: 28rpx;
						border-radius: 20rpx;
						background-color: #F1F1F1;

						view {
							font-size: 20rpx;
							color: #999999;

							&:first-child {
								font-size: 28rpx;
								color: #333333;
								margin-bottom: 10rpx;
							}
						}

						image {
							padding: 10rpx 0;
							width: 61rpx;
							height: 63rpx
						}
					}

					.active {
						position: relative;
						height: 150rpx;
						padding: 20rpx 0;
						border-radius: 20rpx;
						background-color: #F94D39;

						view {
							padding-left: 10rpx;
							font-size: 22rpx;
							color: #FFFFFF;

							&:first-child {
								margin-bottom: 10rpx;
								font-size: 26rpx;
							}
						}

						image {
							position: absolute;
							right: 0;
							bottom: 0;
							width: 75rpx;
							height: 63rpx
						}
					}
				}
			}

			.btn {
				margin: 10rpx 30rpx 30rpx 30rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 28rpx;
				color: #FFFFFF;
				background-color: #F10000;
				border-radius: 40rpx;

				&.gray {
					background-color: #DCDCDC;
				}
			}
		}

		.dialog {
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;
			z-index: 99;

			.mask {
				position: absolute;
				z-index: 9;
				width: 100%;
				height: 100%;
				background-color: rgba(0, 0, 0, 0.5);
			}

			.container {
				position: absolute;
				z-index: 99;
				left: 106rpx;
				width: 548rpx;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: space-between;
				padding: 200rpx 0;
				box-sizing: border-box;

				.info {
					position: absolute;
					z-index: 99;
					margin-top: 390rpx;
					text-align: center;

					.btn {
						margin: 0 auto;
						margin-top: 20rpx;
						width: 200rpx;
						height: 70rpx;
						line-height: 70rpx;
						text-align: center;
						color: #FFFFFF;
						background-color: #F94D39;
						border-radius: 35rpx;
					}

					view {
						font-size: 28rpx;
						color: #666666;

						&:first-child {
							margin-bottom: 10rpx;
							font-size: 36rpx;
							color: #333333;
						}

						text {
							color: #F10000;
						}
					}
				}

				icon {
					position: absolute;
					right: 0;
				}

				image {
					width: 100%;
				}
			}
		}
	}
</style>